package com.ruoyi.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductDictGas;
import com.ruoyi.product.service.IProductDictGasService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 气体主数据Controller
 * 
 * @author ruoyi
 * @date 2023-01-14
 */
@Controller
@RequestMapping("/product/gas")
public class ProductDictGasController extends BaseController
{
    private String prefix = "product/gas";

    @Autowired
    private IProductDictGasService productDictGasService;

    @RequiresPermissions("product:gas:view")
    @GetMapping()
    public String gas()
    {
        return prefix + "/gas";
    }

    /**
     * 查询气体主数据列表
     */
    @RequiresPermissions("product:gas:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductDictGas productDictGas)
    {
        startPage();
        List<ProductDictGas> list = productDictGasService.selectProductDictGasList(productDictGas);
        return getDataTable(list);
    }

    /**
     * 导出气体主数据列表
     */
    @RequiresPermissions("product:gas:export")
    @Log(title = "气体主数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductDictGas productDictGas)
    {
        List<ProductDictGas> list = productDictGasService.selectProductDictGasList(productDictGas);
        ExcelUtil<ProductDictGas> util = new ExcelUtil<ProductDictGas>(ProductDictGas.class);
        return util.exportExcel(list, "气体主数据数据");
    }

    /**
     * 新增气体主数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存气体主数据
     */
    @RequiresPermissions("product:gas:add")
    @Log(title = "气体主数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductDictGas productDictGas)
    {
        return toAjax(productDictGasService.insertProductDictGas(productDictGas));
    }

    /**
     * 修改气体主数据
     */
    @RequiresPermissions("product:gas:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductDictGas productDictGas = productDictGasService.selectProductDictGasById(id);
        mmap.put("productDictGas", productDictGas);
        return prefix + "/edit";
    }

    /**
     * 修改保存气体主数据
     */
    @RequiresPermissions("product:gas:edit")
    @Log(title = "气体主数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductDictGas productDictGas)
    {
        return toAjax(productDictGasService.updateProductDictGas(productDictGas));
    }

    /**
     * 删除气体主数据
     */
    @RequiresPermissions("product:gas:remove")
    @Log(title = "气体主数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productDictGasService.deleteProductDictGasByIds(ids));
    }
}
